package com.drugmanage.controller;

import com.drugmanage.Base.BaseController;
import com.drugmanage.annotations.Pms;
import com.drugmanage.entity.Role;
import com.drugmanage.model.ResultInfo;
import com.drugmanage.query.RoleQuery;
import com.drugmanage.service.IRoleService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("user/role")
public class RoleController extends BaseController{
    @Resource
    private IRoleService roleService;

    @RequestMapping("index")
    public String index(){
        return "role";
    }

    @RequestMapping("queryRolesByParams")
    @ResponseBody
    @Pms(acl = "888801")
    public Map<String,Object> queryRoleByParams(RoleQuery roleQuery){
        return roleService.queryForPage(roleQuery);
    }

    @RequestMapping("saveRole")
    @ResponseBody
    public ResultInfo saveRole(Role role){
        roleService.saveRole(role);
        return success("添加成功");
    }

    @RequestMapping("updateRole")
    @ResponseBody
    public ResultInfo updateRole(Role role){
        roleService.updateRole(role);
        return success("修改成功");
    }

    @RequestMapping("deleteRole")
    @ResponseBody
    public ResultInfo deleteRole(Integer[] ids){
        roleService.deleteRoles(ids[0]);
        return success("删除成功");
    }

    @RequestMapping("addGrant")
    @ResponseBody
    public ResultInfo addGrant(Integer rid,Integer[] moduleIds){
        roleService.addGrant(rid,moduleIds);
        return success("授权成功");
    }

    @RequestMapping("queryAllRoles")
    @ResponseBody
    public List<Role> queryAllRoles(){
        return roleService.queryAllRoles();
    }
}
